{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T07:34:35.585781Z",
     "start_time": "2018-11-05T07:34:34.488179Z"
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "from IPython.core.interactiveshell import InteractiveShell\n",
    "InteractiveShell.ast_node_interactivity = \"all\"\n",
    "\n",
    "import os\n",
    "import ast\n",
    "import datetime as dt\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['figure.figsize'] = [16, 10]\n",
    "plt.rcParams['font.size'] = 14\n",
    "\n",
    "import seaborn as sns\n",
    "import cv2\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "import glob\n",
    "\n",
    "import numpy as np\n",
    "from PIL import Image, ImageDraw\n",
    "\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "\n",
    "import torch\n",
    "import torchvision.models as models\n",
    "import torchvision.transforms as transforms\n",
    "import torchvision.datasets as datasets\n",
    "import torch.nn as nn\n",
    "import torch.optim as optim\n",
    "from torch.autograd import Variable\n",
    "from torch.utils.data.dataset import Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T09:02:50.595432Z",
     "start_time": "2018-11-05T09:02:50.573298Z"
    }
   },
   "outputs": [],
   "source": [
    "def draw_cv2(raw_strokes, size=256, lw=6, time_color=True):\n",
    "    BASE_SIZE = 299\n",
    "    img = np.zeros((BASE_SIZE, BASE_SIZE), np.uint8)\n",
    "    for t, stroke in enumerate(eval(raw_strokes)):\n",
    "        \n",
    "        str_len = len(stroke[0])\n",
    "        for i in range(len(stroke[0]) - 1):\n",
    "            \n",
    "            if np.random.uniform() > 0.95:\n",
    "                continue\n",
    "            \n",
    "            color = 255 - min(t, 10) * 13 if time_color else 255\n",
    "            _ = cv2.line(img, (stroke[0][i] + 22, stroke[1][i]  + 22),\n",
    "                         (stroke[0][i + 1] + 22, stroke[1][i + 1] + 22), color, lw)\n",
    "    \n",
    "    if size != BASE_SIZE:\n",
    "        return cv2.resize(img, (size, size))\n",
    "    else:\n",
    "        return img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T09:24:29.210883Z",
     "start_time": "2018-11-05T09:22:41.643272Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Reading...', '../input/train_simplified/eye.csv')\n",
      "('Reading...', '../input/train_simplified/castle.csv')\n",
      "('Reading...', '../input/train_simplified/pizza.csv')\n",
      "('Reading...', '../input/train_simplified/umbrella.csv')\n",
      "('Reading...', '../input/train_simplified/bat.csv')\n",
      "('Reading...', '../input/train_simplified/hot tub.csv')\n",
      "('Reading...', '../input/train_simplified/diving board.csv')\n",
      "('Reading...', '../input/train_simplified/wine bottle.csv')\n",
      "('Reading...', '../input/train_simplified/butterfly.csv')\n",
      "('Reading...', '../input/train_simplified/bread.csv')\n",
      "('Reading...', '../input/train_simplified/television.csv')\n",
      "('Reading...', '../input/train_simplified/peas.csv')\n",
      "('Reading...', '../input/train_simplified/binoculars.csv')\n",
      "('Reading...', '../input/train_simplified/basket.csv')\n",
      "('Reading...', '../input/train_simplified/steak.csv')\n",
      "('Reading...', '../input/train_simplified/eyeglasses.csv')\n",
      "('Reading...', '../input/train_simplified/backpack.csv')\n",
      "('Reading...', '../input/train_simplified/teddy-bear.csv')\n",
      "('Reading...', '../input/train_simplified/grass.csv')\n",
      "('Reading...', '../input/train_simplified/canoe.csv')\n",
      "('Reading...', '../input/train_simplified/power outlet.csv')\n",
      "('Reading...', '../input/train_simplified/car.csv')\n",
      "('Reading...', '../input/train_simplified/keyboard.csv')\n",
      "('Reading...', '../input/train_simplified/parachute.csv')\n",
      "('Reading...', '../input/train_simplified/spreadsheet.csv')\n",
      "('Reading...', '../input/train_simplified/snowflake.csv')\n",
      "('Reading...', '../input/train_simplified/pond.csv')\n",
      "('Reading...', '../input/train_simplified/airplane.csv')\n",
      "('Reading...', '../input/train_simplified/postcard.csv')\n",
      "('Reading...', '../input/train_simplified/lobster.csv')\n",
      "('Reading...', '../input/train_simplified/peanut.csv')\n",
      "('Reading...', '../input/train_simplified/broom.csv')\n",
      "('Reading...', '../input/train_simplified/mouse.csv')\n",
      "('Reading...', '../input/train_simplified/bathtub.csv')\n",
      "('Reading...', '../input/train_simplified/hot dog.csv')\n",
      "('Reading...', '../input/train_simplified/chandelier.csv')\n",
      "('Reading...', '../input/train_simplified/cat.csv')\n",
      "('Reading...', '../input/train_simplified/cello.csv')\n",
      "('Reading...', '../input/train_simplified/scissors.csv')\n",
      "('Reading...', '../input/train_simplified/horse.csv')\n",
      "('Reading...', '../input/train_simplified/bed.csv')\n",
      "('Reading...', '../input/train_simplified/tractor.csv')\n",
      "('Reading...', '../input/train_simplified/pliers.csv')\n",
      "('Reading...', '../input/train_simplified/chair.csv')\n",
      "('Reading...', '../input/train_simplified/baseball.csv')\n",
      "('Reading...', '../input/train_simplified/paintbrush.csv')\n",
      "('Reading...', '../input/train_simplified/stereo.csv')\n",
      "('Reading...', '../input/train_simplified/bulldozer.csv')\n",
      "('Reading...', '../input/train_simplified/rhinoceros.csv')\n",
      "('Reading...', '../input/train_simplified/sandwich.csv')\n",
      "('Reading...', '../input/train_simplified/vase.csv')\n",
      "('Reading...', '../input/train_simplified/campfire.csv')\n",
      "('Reading...', '../input/train_simplified/basketball.csv')\n",
      "('Reading...', '../input/train_simplified/coffee cup.csv')\n",
      "('Reading...', '../input/train_simplified/sleeping bag.csv')\n",
      "('Reading...', '../input/train_simplified/streetlight.csv')\n",
      "('Reading...', '../input/train_simplified/zebra.csv')\n",
      "('Reading...', '../input/train_simplified/see saw.csv')\n",
      "('Reading...', '../input/train_simplified/axe.csv')\n",
      "('Reading...', '../input/train_simplified/hedgehog.csv')\n",
      "('Reading...', '../input/train_simplified/radio.csv')\n",
      "('Reading...', '../input/train_simplified/grapes.csv')\n",
      "('Reading...', '../input/train_simplified/soccer ball.csv')\n",
      "('Reading...', '../input/train_simplified/ceiling fan.csv')\n",
      "('Reading...', '../input/train_simplified/skyscraper.csv')\n",
      "('Reading...', '../input/train_simplified/frog.csv')\n",
      "('Reading...', '../input/train_simplified/snail.csv')\n",
      "('Reading...', '../input/train_simplified/dresser.csv')\n",
      "('Reading...', '../input/train_simplified/goatee.csv')\n",
      "('Reading...', '../input/train_simplified/sink.csv')\n",
      "('Reading...', '../input/train_simplified/apple.csv')\n",
      "('Reading...', '../input/train_simplified/The Mona Lisa.csv')\n",
      "('Reading...', '../input/train_simplified/house.csv')\n",
      "('Reading...', '../input/train_simplified/hexagon.csv')\n",
      "('Reading...', '../input/train_simplified/circle.csv')\n",
      "('Reading...', '../input/train_simplified/rain.csv')\n",
      "('Reading...', '../input/train_simplified/boomerang.csv')\n",
      "('Reading...', '../input/train_simplified/train.csv')\n",
      "('Reading...', '../input/train_simplified/kangaroo.csv')\n",
      "('Reading...', '../input/train_simplified/rake.csv')\n",
      "('Reading...', '../input/train_simplified/arm.csv')\n",
      "('Reading...', '../input/train_simplified/headphones.csv')\n",
      "('Reading...', '../input/train_simplified/cooler.csv')\n",
      "('Reading...', '../input/train_simplified/sock.csv')\n",
      "('Reading...', '../input/train_simplified/rainbow.csv')\n",
      "('Reading...', '../input/train_simplified/cloud.csv')\n",
      "('Reading...', '../input/train_simplified/hockey puck.csv')\n",
      "('Reading...', '../input/train_simplified/bird.csv')\n",
      "('Reading...', '../input/train_simplified/bottlecap.csv')\n",
      "('Reading...', '../input/train_simplified/stove.csv')\n",
      "('Reading...', '../input/train_simplified/bowtie.csv')\n",
      "('Reading...', '../input/train_simplified/duck.csv')\n",
      "('Reading...', '../input/train_simplified/carrot.csv')\n",
      "('Reading...', '../input/train_simplified/skateboard.csv')\n",
      "('Reading...', '../input/train_simplified/hot air balloon.csv')\n",
      "('Reading...', '../input/train_simplified/onion.csv')\n",
      "('Reading...', '../input/train_simplified/hockey stick.csv')\n",
      "('Reading...', '../input/train_simplified/house plant.csv')\n",
      "('Reading...', '../input/train_simplified/underwear.csv')\n",
      "('Reading...', '../input/train_simplified/shovel.csv')\n",
      "('Reading...', '../input/train_simplified/picture frame.csv')\n",
      "('Reading...', '../input/train_simplified/pool.csv')\n",
      "('Reading...', '../input/train_simplified/camouflage.csv')\n",
      "('Reading...', '../input/train_simplified/elephant.csv')\n",
      "('Reading...', '../input/train_simplified/stitches.csv')\n",
      "('Reading...', '../input/train_simplified/whale.csv')\n",
      "('Reading...', '../input/train_simplified/sun.csv')\n",
      "('Reading...', '../input/train_simplified/moon.csv')\n",
      "('Reading...', '../input/train_simplified/broccoli.csv')\n",
      "('Reading...', '../input/train_simplified/rabbit.csv')\n",
      "('Reading...', '../input/train_simplified/rollerskates.csv')\n",
      "('Reading...', '../input/train_simplified/fence.csv')\n",
      "('Reading...', '../input/train_simplified/squirrel.csv')\n",
      "('Reading...', '../input/train_simplified/feather.csv')\n",
      "('Reading...', '../input/train_simplified/roller coaster.csv')\n",
      "('Reading...', '../input/train_simplified/door.csv')\n",
      "('Reading...', '../input/train_simplified/flamingo.csv')\n",
      "('Reading...', '../input/train_simplified/popsicle.csv')\n",
      "('Reading...', '../input/train_simplified/waterslide.csv')\n",
      "('Reading...', '../input/train_simplified/fireplace.csv')\n",
      "('Reading...', '../input/train_simplified/hamburger.csv')\n",
      "('Reading...', '../input/train_simplified/windmill.csv')\n",
      "('Reading...', '../input/train_simplified/bus.csv')\n",
      "('Reading...', '../input/train_simplified/sweater.csv')\n",
      "('Reading...', '../input/train_simplified/snake.csv')\n",
      "('Reading...', '../input/train_simplified/river.csv')\n",
      "('Reading...', '../input/train_simplified/drums.csv')\n",
      "('Reading...', '../input/train_simplified/garden.csv')\n",
      "('Reading...', '../input/train_simplified/clock.csv')\n",
      "('Reading...', '../input/train_simplified/bear.csv')\n",
      "('Reading...', '../input/train_simplified/baseball bat.csv')\n",
      "('Reading...', '../input/train_simplified/bicycle.csv')\n",
      "('Reading...', '../input/train_simplified/fire hydrant.csv')\n",
      "('Reading...', '../input/train_simplified/crocodile.csv')\n",
      "('Reading...', '../input/train_simplified/parrot.csv')\n",
      "('Reading...', '../input/train_simplified/angel.csv')\n",
      "('Reading...', '../input/train_simplified/octagon.csv')\n",
      "('Reading...', '../input/train_simplified/giraffe.csv')\n",
      "('Reading...', '../input/train_simplified/calculator.csv')\n",
      "('Reading...', '../input/train_simplified/bush.csv')\n",
      "('Reading...', '../input/train_simplified/pineapple.csv')\n",
      "('Reading...', '../input/train_simplified/dragon.csv')\n",
      "('Reading...', '../input/train_simplified/tent.csv')\n",
      "('Reading...', '../input/train_simplified/paper clip.csv')\n",
      "('Reading...', '../input/train_simplified/snorkel.csv')\n",
      "('Reading...', '../input/train_simplified/shorts.csv')\n",
      "('Reading...', '../input/train_simplified/tornado.csv')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Reading...', '../input/train_simplified/beard.csv')\n",
      "('Reading...', '../input/train_simplified/hand.csv')\n",
      "('Reading...', '../input/train_simplified/moustache.csv')\n",
      "('Reading...', '../input/train_simplified/screwdriver.csv')\n",
      "('Reading...', '../input/train_simplified/nose.csv')\n",
      "('Reading...', '../input/train_simplified/eraser.csv')\n",
      "('Reading...', '../input/train_simplified/truck.csv')\n",
      "('Reading...', '../input/train_simplified/sea turtle.csv')\n",
      "('Reading...', '../input/train_simplified/penguin.csv')\n",
      "('Reading...', '../input/train_simplified/ant.csv')\n",
      "('Reading...', '../input/train_simplified/motorbike.csv')\n",
      "('Reading...', '../input/train_simplified/tree.csv')\n",
      "('Reading...', '../input/train_simplified/camel.csv')\n",
      "('Reading...', '../input/train_simplified/toe.csv')\n",
      "('Reading...', '../input/train_simplified/pillow.csv')\n",
      "('Reading...', '../input/train_simplified/yoga.csv')\n",
      "('Reading...', '../input/train_simplified/lantern.csv')\n",
      "('Reading...', '../input/train_simplified/potato.csv')\n",
      "('Reading...', '../input/train_simplified/cruise ship.csv')\n",
      "('Reading...', '../input/train_simplified/pickup truck.csv')\n",
      "('Reading...', '../input/train_simplified/pig.csv')\n",
      "('Reading...', '../input/train_simplified/foot.csv')\n",
      "('Reading...', '../input/train_simplified/mosquito.csv')\n",
      "('Reading...', '../input/train_simplified/tiger.csv')\n",
      "('Reading...', '../input/train_simplified/octopus.csv')\n",
      "('Reading...', '../input/train_simplified/diamond.csv')\n",
      "('Reading...', '../input/train_simplified/wine glass.csv')\n",
      "('Reading...', '../input/train_simplified/crab.csv')\n",
      "('Reading...', '../input/train_simplified/blackberry.csv')\n",
      "('Reading...', '../input/train_simplified/submarine.csv')\n",
      "('Reading...', '../input/train_simplified/bee.csv')\n",
      "('Reading...', '../input/train_simplified/The Eiffel Tower.csv')\n",
      "('Reading...', '../input/train_simplified/finger.csv')\n",
      "('Reading...', '../input/train_simplified/belt.csv')\n",
      "('Reading...', '../input/train_simplified/jail.csv')\n",
      "('Reading...', '../input/train_simplified/bracelet.csv')\n",
      "('Reading...', '../input/train_simplified/megaphone.csv')\n",
      "('Reading...', '../input/train_simplified/saw.csv')\n",
      "('Reading...', '../input/train_simplified/microwave.csv')\n",
      "('Reading...', '../input/train_simplified/pants.csv')\n",
      "('Reading...', '../input/train_simplified/The Great Wall of China.csv')\n",
      "('Reading...', '../input/train_simplified/mermaid.csv')\n",
      "('Reading...', '../input/train_simplified/ear.csv')\n",
      "('Reading...', '../input/train_simplified/firetruck.csv')\n",
      "('Reading...', '../input/train_simplified/ocean.csv')\n",
      "('Reading...', '../input/train_simplified/birthday cake.csv')\n",
      "('Reading...', '../input/train_simplified/table.csv')\n",
      "('Reading...', '../input/train_simplified/star.csv')\n",
      "('Reading...', '../input/train_simplified/cannon.csv')\n",
      "('Reading...', '../input/train_simplified/envelope.csv')\n",
      "('Reading...', '../input/train_simplified/skull.csv')\n",
      "('Reading...', '../input/train_simplified/beach.csv')\n",
      "('Reading...', '../input/train_simplified/cactus.csv')\n",
      "('Reading...', '../input/train_simplified/alarm clock.csv')\n",
      "('Reading...', '../input/train_simplified/shoe.csv')\n",
      "('Reading...', '../input/train_simplified/map.csv')\n",
      "('Reading...', '../input/train_simplified/nail.csv')\n",
      "('Reading...', '../input/train_simplified/stairs.csv')\n",
      "('Reading...', '../input/train_simplified/blueberry.csv')\n",
      "('Reading...', '../input/train_simplified/mailbox.csv')\n",
      "('Reading...', '../input/train_simplified/remote control.csv')\n",
      "('Reading...', '../input/train_simplified/hourglass.csv')\n",
      "('Reading...', '../input/train_simplified/trombone.csv')\n",
      "('Reading...', '../input/train_simplified/watermelon.csv')\n",
      "('Reading...', '../input/train_simplified/suitcase.csv')\n",
      "('Reading...', '../input/train_simplified/telephone.csv')\n",
      "('Reading...', '../input/train_simplified/golf club.csv')\n",
      "('Reading...', '../input/train_simplified/sword.csv')\n",
      "('Reading...', '../input/train_simplified/bridge.csv')\n",
      "('Reading...', '../input/train_simplified/brain.csv')\n",
      "('Reading...', '../input/train_simplified/helmet.csv')\n",
      "('Reading...', '../input/train_simplified/spoon.csv')\n",
      "('Reading...', '../input/train_simplified/dishwasher.csv')\n",
      "('Reading...', '../input/train_simplified/hospital.csv')\n",
      "('Reading...', '../input/train_simplified/couch.csv')\n",
      "('Reading...', '../input/train_simplified/donut.csv')\n",
      "('Reading...', '../input/train_simplified/traffic light.csv')\n",
      "('Reading...', '../input/train_simplified/barn.csv')\n",
      "('Reading...', '../input/train_simplified/banana.csv')\n",
      "('Reading...', '../input/train_simplified/squiggle.csv')\n",
      "('Reading...', '../input/train_simplified/wheel.csv')\n",
      "('Reading...', '../input/train_simplified/necklace.csv')\n",
      "('Reading...', '../input/train_simplified/violin.csv')\n",
      "('Reading...', '../input/train_simplified/hurricane.csv')\n",
      "('Reading...', '../input/train_simplified/matches.csv')\n",
      "('Reading...', '../input/train_simplified/crown.csv')\n",
      "('Reading...', '../input/train_simplified/candle.csv')\n",
      "('Reading...', '../input/train_simplified/bucket.csv')\n",
      "('Reading...', '../input/train_simplified/anvil.csv')\n",
      "('Reading...', '../input/train_simplified/dumbbell.csv')\n",
      "('Reading...', '../input/train_simplified/fork.csv')\n",
      "('Reading...', '../input/train_simplified/toothpaste.csv')\n",
      "('Reading...', '../input/train_simplified/compass.csv')\n",
      "('Reading...', '../input/train_simplified/key.csv')\n",
      "('Reading...', '../input/train_simplified/strawberry.csv')\n",
      "('Reading...', '../input/train_simplified/teapot.csv')\n",
      "('Reading...', '../input/train_simplified/pencil.csv')\n",
      "('Reading...', '../input/train_simplified/light bulb.csv')\n",
      "('Reading...', '../input/train_simplified/sheep.csv')\n",
      "('Reading...', '../input/train_simplified/helicopter.csv')\n",
      "('Reading...', '../input/train_simplified/smiley face.csv')\n",
      "('Reading...', '../input/train_simplified/van.csv')\n",
      "('Reading...', '../input/train_simplified/dolphin.csv')\n",
      "('Reading...', '../input/train_simplified/spider.csv')\n",
      "('Reading...', '../input/train_simplified/fish.csv')\n",
      "('Reading...', '../input/train_simplified/toothbrush.csv')\n",
      "('Reading...', '../input/train_simplified/marker.csv')\n",
      "('Reading...', '../input/train_simplified/flying saucer.csv')\n",
      "('Reading...', '../input/train_simplified/cookie.csv')\n",
      "('Reading...', '../input/train_simplified/scorpion.csv')\n",
      "('Reading...', '../input/train_simplified/palm tree.csv')\n",
      "('Reading...', '../input/train_simplified/toaster.csv')\n",
      "('Reading...', '../input/train_simplified/sailboat.csv')\n",
      "('Reading...', '../input/train_simplified/asparagus.csv')\n",
      "('Reading...', '../input/train_simplified/pear.csv')\n",
      "('Reading...', '../input/train_simplified/elbow.csv')\n",
      "('Reading...', '../input/train_simplified/cup.csv')\n",
      "('Reading...', '../input/train_simplified/dog.csv')\n",
      "('Reading...', '../input/train_simplified/piano.csv')\n",
      "('Reading...', '../input/train_simplified/mushroom.csv')\n",
      "('Reading...', '../input/train_simplified/snowman.csv')\n",
      "('Reading...', '../input/train_simplified/line.csv')\n",
      "('Reading...', '../input/train_simplified/mouth.csv')\n",
      "('Reading...', '../input/train_simplified/calendar.csv')\n",
      "('Reading...', '../input/train_simplified/saxophone.csv')\n",
      "('Reading...', '../input/train_simplified/paint can.csv')\n",
      "('Reading...', '../input/train_simplified/panda.csv')\n",
      "('Reading...', '../input/train_simplified/hat.csv')\n",
      "('Reading...', '../input/train_simplified/drill.csv')\n",
      "('Reading...', '../input/train_simplified/leg.csv')\n",
      "('Reading...', '../input/train_simplified/knee.csv')\n",
      "('Reading...', '../input/train_simplified/lightning.csv')\n",
      "('Reading...', '../input/train_simplified/ice cream.csv')\n",
      "('Reading...', '../input/train_simplified/hammer.csv')\n",
      "('Reading...', '../input/train_simplified/frying pan.csv')\n",
      "('Reading...', '../input/train_simplified/camera.csv')\n",
      "('Reading...', '../input/train_simplified/mountain.csv')\n",
      "('Reading...', '../input/train_simplified/flip flops.csv')\n",
      "('Reading...', '../input/train_simplified/shark.csv')\n",
      "('Reading...', '../input/train_simplified/swing set.csv')\n",
      "('Reading...', '../input/train_simplified/bench.csv')\n",
      "('Reading...', '../input/train_simplified/string bean.csv')\n",
      "('Reading...', '../input/train_simplified/ladder.csv')\n",
      "('Reading...', '../input/train_simplified/cake.csv')\n",
      "('Reading...', '../input/train_simplified/jacket.csv')\n",
      "('Reading...', '../input/train_simplified/flower.csv')\n",
      "('Reading...', '../input/train_simplified/fan.csv')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Reading...', '../input/train_simplified/laptop.csv')\n",
      "('Reading...', '../input/train_simplified/cell phone.csv')\n",
      "('Reading...', '../input/train_simplified/mug.csv')\n",
      "('Reading...', '../input/train_simplified/stethoscope.csv')\n",
      "('Reading...', '../input/train_simplified/guitar.csv')\n",
      "('Reading...', '../input/train_simplified/tooth.csv')\n",
      "('Reading...', '../input/train_simplified/square.csv')\n",
      "('Reading...', '../input/train_simplified/lipstick.csv')\n",
      "('Reading...', '../input/train_simplified/purse.csv')\n",
      "('Reading...', '../input/train_simplified/raccoon.csv')\n",
      "('Reading...', '../input/train_simplified/passport.csv')\n",
      "('Reading...', '../input/train_simplified/oven.csv')\n",
      "('Reading...', '../input/train_simplified/book.csv')\n",
      "('Reading...', '../input/train_simplified/clarinet.csv')\n",
      "('Reading...', '../input/train_simplified/crayon.csv')\n",
      "('Reading...', '../input/train_simplified/face.csv')\n",
      "('Reading...', '../input/train_simplified/church.csv')\n",
      "('Reading...', '../input/train_simplified/stop sign.csv')\n",
      "('Reading...', '../input/train_simplified/microphone.csv')\n",
      "('Reading...', '../input/train_simplified/lollipop.csv')\n",
      "('Reading...', '../input/train_simplified/swan.csv')\n",
      "('Reading...', '../input/train_simplified/leaf.csv')\n",
      "('Reading...', '../input/train_simplified/computer.csv')\n",
      "('Reading...', '../input/train_simplified/lion.csv')\n",
      "('Reading...', '../input/train_simplified/lighthouse.csv')\n",
      "('Reading...', '../input/train_simplified/t-shirt.csv')\n",
      "('Reading...', '../input/train_simplified/ambulance.csv')\n",
      "('Reading...', '../input/train_simplified/washing machine.csv')\n",
      "('Reading...', '../input/train_simplified/police car.csv')\n",
      "('Reading...', '../input/train_simplified/garden hose.csv')\n",
      "('Reading...', '../input/train_simplified/owl.csv')\n",
      "('Reading...', '../input/train_simplified/school bus.csv')\n",
      "('Reading...', '../input/train_simplified/cow.csv')\n",
      "('Reading...', '../input/train_simplified/triangle.csv')\n",
      "('Reading...', '../input/train_simplified/toilet.csv')\n",
      "('Reading...', '../input/train_simplified/monkey.csv')\n",
      "('Reading...', '../input/train_simplified/wristwatch.csv')\n",
      "('Reading...', '../input/train_simplified/floor lamp.csv')\n",
      "('Reading...', '../input/train_simplified/bandage.csv')\n",
      "('Reading...', '../input/train_simplified/harp.csv')\n",
      "('Reading...', '../input/train_simplified/flashlight.csv')\n",
      "('Reading...', '../input/train_simplified/tennis racquet.csv')\n",
      "('Reading...', '../input/train_simplified/trumpet.csv')\n",
      "('Reading...', '../input/train_simplified/zigzag.csv')\n",
      "('Reading...', '../input/train_simplified/animal migration.csv')\n",
      "('Reading...', '../input/train_simplified/speedboat.csv')\n"
     ]
    }
   ],
   "source": [
    "CLASSES_CSV = glob.glob('../input/train_simplified/*.csv')\n",
    "CLASSES = [x.split('/')[-1][:-4] for x in CLASSES_CSV]\n",
    "\n",
    "# 读取单个csv文件\n",
    "def read_df(path, nrows):\n",
    "    print('Reading...', path)\n",
    "    if isinstance(nrows, int):\n",
    "        return pd.read_csv(path, nrows=nrows, parse_dates=['timestamp'])\n",
    "    else:\n",
    "        return pd.read_csv(path, parse_dates=['timestamp'])\n",
    "\n",
    "# 读取多个csv文件\n",
    "def contcat_df(paths, nrows):\n",
    "    dfs = []\n",
    "    for path in paths:\n",
    "        dfs.append(read_df(path, nrows))\n",
    "    return pd.concat(dfs, axis=0, ignore_index=True)\n",
    "\n",
    "df = contcat_df(CLASSES_CSV, 50000)\n",
    "df = df.reindex(np.random.permutation(df.index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T09:02:53.410723Z",
     "start_time": "2018-11-05T09:02:53.390748Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        ...,\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.]],\n",
       "\n",
       "       [[0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        ...,\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.]],\n",
       "\n",
       "       [[0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        ...,\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.]],\n",
       "\n",
       "       ...,\n",
       "\n",
       "       [[0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        ...,\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.]],\n",
       "\n",
       "       [[0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        ...,\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.]],\n",
       "\n",
       "       [[0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        ...,\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.],\n",
       "        [0., 0., 0.]]])"
      ]
     },
     "execution_count": 222,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img = np.zeros((128, 128, 3))\n",
    "\n",
    "img[:, :, 0] = draw_cv2(df['drawing'].iloc[1902], 128)\n",
    "img[:, :, 1] = img[:, :, 0]\n",
    "img[:, :, 2] = img[:, :, 0]\n",
    "# img = Image.fromarray(np.uint8(img))\n",
    "\n",
    "img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T09:01:43.839656Z",
     "start_time": "2018-11-05T09:01:43.828639Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "transform4 = transforms.Compose([\n",
    "#     transforms.RandomHorizontalFlip(),\n",
    "#     transforms.RandomVerticalFlip(),\n",
    "    transforms.RandomAffine(10, scale=[0.8, 1.05], translate=[0.05, 0.1]),\n",
    "#     transforms.RandomRotation([-30, 30]),\n",
    "    transforms.ToTensor(), \n",
    "    transforms.ToPILImage(),\n",
    "    ]\n",
    ")\n",
    "img_trans = transform4(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T08:58:26.566808Z",
     "start_time": "2018-11-05T08:58:26.550699Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 0.00392157, 0.01176471, 0.01960784, 0.02352941,\n",
       "       0.02745098, 0.03137255, 0.03529412, 0.04705882, 0.05098039,\n",
       "       0.05490196, 0.05882353, 0.0627451 , 0.07450981, 0.08235294,\n",
       "       0.08627451, 0.09019608, 0.09411765, 0.09803922, 0.10588235,\n",
       "       0.10980392, 0.11372549, 0.12156863, 0.1254902 , 0.12941177,\n",
       "       0.14117648, 0.14509805, 0.14901961, 0.15294118, 0.15686275,\n",
       "       0.16470589, 0.17254902, 0.1764706 , 0.18039216, 0.18431373,\n",
       "       0.19215687, 0.2       , 0.20392157, 0.21176471, 0.21960784,\n",
       "       0.23137255, 0.23921569, 0.24313726, 0.24705882, 0.2509804 ,\n",
       "       0.25490198, 0.2627451 , 0.27058825, 0.27450982, 0.2784314 ,\n",
       "       0.28235295, 0.28627452, 0.29411766, 0.29803923, 0.3019608 ,\n",
       "       0.31764707, 0.32156864, 0.3254902 , 0.32941177, 0.33333334,\n",
       "       0.3372549 , 0.35686275, 0.3647059 , 0.36862746, 0.37254903,\n",
       "       0.38039216, 0.38431373, 0.3882353 , 0.39215687, 0.39607844,\n",
       "       0.4       , 0.40784314, 0.4117647 , 0.41568628, 0.42352942,\n",
       "       0.42745098, 0.43137255, 0.4392157 , 0.44313726, 0.44705883,\n",
       "       0.45490196, 0.45882353, 0.4627451 , 0.46666667, 0.4745098 ,\n",
       "       0.47843137, 0.48235294, 0.4862745 , 0.49019608, 0.49411765,\n",
       "       0.5019608 , 0.5058824 , 0.5176471 , 0.52156866, 0.5294118 ,\n",
       "       0.53333336, 0.5372549 , 0.54901963, 0.56078434, 0.5647059 ,\n",
       "       0.5686275 , 0.57254905, 0.5882353 , 0.5921569 , 0.59607846,\n",
       "       0.6       , 0.6039216 , 0.60784316, 0.627451  , 0.63529414,\n",
       "       0.6392157 , 0.64705884, 0.654902  , 0.65882355, 0.6745098 ,\n",
       "       0.6901961 , 0.69411767, 0.69803923, 0.7019608 , 0.70980394,\n",
       "       0.7137255 , 0.7176471 , 0.72156864, 0.7254902 , 0.7294118 ,\n",
       "       0.73333335, 0.74509805, 0.7490196 , 0.7529412 , 0.7607843 ,\n",
       "       0.76862746, 0.77254903, 0.78039217, 0.7882353 , 0.7921569 ,\n",
       "       0.79607844, 0.8039216 , 0.80784315, 0.8156863 , 0.81960785,\n",
       "       0.8235294 , 0.83137256, 0.8352941 , 0.8392157 , 0.84313726,\n",
       "       0.84705883, 0.8509804 , 0.85490197, 0.85882354, 0.8666667 ,\n",
       "       0.87058824, 0.8745098 , 0.8784314 , 0.88235295, 0.8862745 ,\n",
       "       0.89411765, 0.8980392 , 0.90588236, 0.9098039 , 0.9137255 ,\n",
       "       0.92156863, 0.9254902 , 0.93333334, 0.9411765 , 0.94509804,\n",
       "       0.9490196 , 0.95686275, 0.9607843 , 0.972549  , 0.9764706 ,\n",
       "       0.9843137 , 0.99215686, 1.        ], dtype=float32)"
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(img_trans.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T07:55:37.378766Z",
     "start_time": "2018-11-05T07:55:37.373207Z"
    }
   },
   "outputs": [],
   "source": [
    "img_border = np.where(img != 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T07:55:53.976182Z",
     "start_time": "2018-11-05T07:55:53.966531Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "119"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img_border[1].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T09:05:28.779101Z",
     "start_time": "2018-11-05T09:05:28.639832Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[  0.   1.   3.   4.   5.   6.   7.   8.   9.  10.  12.  13.  14.  15.\n",
      "  16.  18.  19.  21.  22.  23.  24.  25.  26.  27.  28.  29.  31.  32.\n",
      "  33.  35.  36.  37.  38.  39.  40.  42.  44.  45.  46.  47.  49.  51.\n",
      "  52.  56.  59.  60.  61.  62.  63.  64.  65.  67.  69.  70.  71.  72.\n",
      "  73.  75.  77.  81.  82.  83.  84.  85.  86.  91.  93.  94.  95.  97.\n",
      "  98.  99. 100. 101. 102. 103. 104. 105. 106. 108. 110. 112. 113. 114.\n",
      " 117. 118. 119. 121. 122. 123. 125. 126. 128. 129. 132. 133. 135. 136.\n",
      " 137. 140. 141. 142. 143. 144. 145. 146. 150. 151. 152. 153. 154. 155.\n",
      " 156. 160. 162. 164. 165. 167. 168. 172. 176. 177. 178. 179. 180. 181.\n",
      " 182. 183. 184. 185. 186. 187. 190. 191. 192. 193. 194. 196. 197. 199.\n",
      " 200. 201. 202. 203. 205. 206. 208. 209. 210. 211. 212. 213. 214. 215.\n",
      " 216. 217. 218. 219. 221. 222. 223. 224. 225. 226. 228. 229. 231. 232.\n",
      " 233. 235. 236. 238. 241. 242. 244. 245. 246. 248. 251. 253. 255.]\n",
      "[0.00000000e+00 8.20312500e-02 9.76562500e-02 ... 2.54384766e+02\n",
      " 2.54937500e+02 2.55000000e+02]\n"
     ]
    }
   ],
   "source": [
    "def grid_distortion(img, num_steps=10, xsteps=[], ysteps=[], interpolation=cv2.INTER_LINEAR,\n",
    "                    border_mode=cv2.BORDER_REFLECT_101):\n",
    "    \"\"\"\n",
    "    Reference:\n",
    "        http://pythology.blogspot.sg/2014/03/interpolation-on-regular-distorted-grid.html\n",
    "    \"\"\"\n",
    "    height, width = img.shape[:2]\n",
    "\n",
    "    x_step = width // num_steps\n",
    "    xx = np.zeros(width, np.float32)\n",
    "    prev = 0\n",
    "    for idx, x in enumerate(range(0, width, x_step)):\n",
    "        start = x\n",
    "        end = x + x_step\n",
    "        if end > width:\n",
    "            end = width\n",
    "            cur = width\n",
    "        else:\n",
    "            cur = prev + x_step * xsteps[idx]\n",
    "\n",
    "        xx[start:end] = np.linspace(prev, cur, end - start)\n",
    "        prev = cur\n",
    "\n",
    "    y_step = height // num_steps\n",
    "    yy = np.zeros(height, np.float32)\n",
    "    prev = 0\n",
    "    for idx, y in enumerate(range(0, height, y_step)):\n",
    "        start = y\n",
    "        end = y + y_step\n",
    "        if end > height:\n",
    "            end = height\n",
    "            cur = height\n",
    "        else:\n",
    "            cur = prev + y_step * ysteps[idx]\n",
    "\n",
    "        yy[start:end] = np.linspace(prev, cur, end - start)\n",
    "        prev = cur\n",
    "\n",
    "    map_x, map_y = np.meshgrid(xx, yy)\n",
    "    map_x = map_x.astype(np.float32)\n",
    "    map_y = map_y.astype(np.float32)\n",
    "    img = cv2.remap(img, map_x, map_y, interpolation=interpolation, borderMode=border_mode)\n",
    "    return img\n",
    "\n",
    "from scipy.ndimage.filters import gaussian_filter\n",
    "def elastic_transform_fast(image, alpha, sigma, alpha_affine, interpolation=cv2.INTER_NEAREST,\n",
    "                           border_mode=cv2.BORDER_REFLECT_101, random_state=None):\n",
    "    \"\"\"Elastic deformation of images as described in [Simard2003]_ (with modifications).\n",
    "    Based on https://gist.github.com/erniejunior/601cdf56d2b424757de5\n",
    "    .. [Simard2003] Simard, Steinkraus and Platt, \"Best Practices for\n",
    "         Convolutional Neural Networks applied to Visual Document Analysis\", in\n",
    "         Proc. of the International Conference on Document Analysis and\n",
    "         Recognition, 2003.\n",
    "    \"\"\"\n",
    "    if random_state is None:\n",
    "        random_state = np.random.RandomState()\n",
    "\n",
    "    height, width = image.shape[:2]\n",
    "\n",
    "    # Random affine\n",
    "    center_square = np.float32((height, width)) // 2\n",
    "    square_size = min((height, width)) // 3\n",
    "    alpha = float(alpha)\n",
    "    sigma = float(sigma)\n",
    "    alpha_affine = float(alpha_affine)\n",
    "\n",
    "    pts1 = np.float32([center_square + square_size, [center_square[0] + square_size, center_square[1] - square_size],\n",
    "                       center_square - square_size])\n",
    "    pts2 = pts1 + random_state.uniform(-alpha_affine, alpha_affine, size=pts1.shape).astype(np.float32)\n",
    "    matrix = cv2.getAffineTransform(pts1, pts2)\n",
    "\n",
    "    print(np.unique(image[:, :, 0]))\n",
    "    image = cv2.warpAffine(image, matrix, (width, height), flags=interpolation, borderMode=border_mode)\n",
    "    print(np.unique(image[:, :, 0]))\n",
    "    \n",
    "    dx = np.float32(gaussian_filter((random_state.rand(height, width) * 2 - 1), sigma) * alpha)\n",
    "    dy = np.float32(gaussian_filter((random_state.rand(height, width) * 2 - 1), sigma) * alpha)\n",
    "\n",
    "    x, y = np.meshgrid(np.arange(width), np.arange(height))\n",
    "\n",
    "    mapx = np.float32(x + dx)\n",
    "    mapy = np.float32(y + dy)\n",
    "\n",
    "    return cv2.remap(image, mapx, mapy, interpolation, borderMode=border_mode)\n",
    "\n",
    "img2 = elastic_transform_fast(img, alpha=1, sigma=30, alpha_affine=30, interpolation=1, border_mode=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T09:05:28.792177Z",
     "start_time": "2018-11-05T09:05:28.782957Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAAABMXPacAAAUaElEQVR4nO2deVQTxx/AJyEkEYNUOSLKjUexItSriKIitFbxtraVw2Lltfq0gnj1iQe1z6eCFlur+KoFpV4VD1SwgByirQSvUCgIhihHRi4NZDligsn+/hjdX0wCJIFA0P38ld2dmZ3d2Zn5zveYAKCO69evQwg5HE5FRcWFCxfUpjFwzMzMYmNjg4KCIiMj/f39z58/P2HCBD3dy87Orra2NikpiU6n3717VyQSRUREdJrL0dERQkhTe23EiBEAABsbGwAAi8Xq3ur2AJGRkeHh4QCAgICApqYmU1NTAICDgwONRsvJydm/f39DQwOO483NzV2/F4VCCQwMZDKZRUVFN27cGDFiRFVV1cmTJzvN2NTU1O6133//Hb5myJAhXa9lj7Fq1aq6ujrsNSUlJRiGNTY2Ym+Slpa2ffv2rn9bFAolIiJCJBI9e/YsOjpaKBTy+fz33nt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.Image image mode=RGB size=128x128 at 0xA358850>"
      ]
     },
     "execution_count": 252,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Image.fromarray(np.uint8(img2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T08:29:48.253619Z",
     "start_time": "2018-11-05T08:29:48.243692Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.00000000e+00, 1.26953125e-02, 2.92968750e-02, ...,\n",
       "       2.54197266e+02, 2.54656250e+02, 2.55000000e+02])"
      ]
     },
     "execution_count": 169,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(img2[:, :, 0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T08:31:48.433651Z",
     "start_time": "2018-11-05T08:31:48.424223Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6969660210932113"
      ]
     },
     "execution_count": 171,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.uniform()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-05T09:22:36.398417Z",
     "start_time": "2018-11-05T09:22:36.363667Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>countrycode</th>\n",
       "      <th>drawing</th>\n",
       "      <th>key_id</th>\n",
       "      <th>recognized</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>word</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>151378</th>\n",
       "      <td>SE</td>\n",
       "      <td>[[[6, 0, 0, 5, 26, 39, 74, 129, 157, 205, 226,...</td>\n",
       "      <td>5296310389309440</td>\n",
       "      <td>True</td>\n",
       "      <td>2017-03-23 12:35:49.773920</td>\n",
       "      <td>purse</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       countrycode                                            drawing  \\\n",
       "151378          SE  [[[6, 0, 0, 5, 26, 39, 74, 129, 157, 205, 226,...   \n",
       "\n",
       "                  key_id  recognized                  timestamp   word  \n",
       "151378  5296310389309440        True 2017-03-23 12:35:49.773920  purse  "
      ]
     },
     "execution_count": 256,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['key_id'] == 5296310389309440]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
